home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 4.4 KB | 148 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWMemTas.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include <stdlib.h>
-
- #ifndef FWMEMTAS_H
- #include "FWMemTas.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWOBJECH_H
- #include "FWObjecH.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // Memory allocation glue code
- //----------------------------------------------------------------------------------------
-
- static void* OperatorNewHandler(size_t size)
- {
- #ifdef FW_qUsePlatformAlloc
- return ::malloc(size);
- #else
- return FW_CMemoryTaskGlobals::GetMemoryGlobals().gMemoryHeap->Allocate(size);
- #endif
- }
-
- static void OperatorDeleteHandler(void* p)
- {
- #ifdef FW_qUsePlatformAlloc
- ::free(p);
- #else
- FW_CMemoryTaskGlobals::GetMemoryGlobals().gMemoryHeap->Free(p);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemoryTaskGlobals::Initialize()
- //----------------------------------------------------------------------------------------
-
- void FW_CMemoryTaskGlobals::Initialize(FW_SPrivMemoryGlobals& memGlobals)
- {
- memGlobals.gMemoryHeap = 0;
- InitializeMemoryHeap(memGlobals);
- memGlobals.gLastRequested = 0;
- memGlobals.gNewHandler = FW_CMemoryManager::DefaultNewHandler;
-
- FW_SPrivExceptionGlobals excGlobals = FW_CExceptionTaskGlobals::GetExceptionGlobals();
-
- #ifndef FW_qUsePlatformAlloc
- if (excGlobals.gOperatorNewHandler == 0)
- {
- excGlobals.gOperatorNewHandler = &::operator new;
- excGlobals.gOperatorDeleteHandler = &::operator delete;
- }
-
- // Note: Local variables are used here because it illegal to use the address of an
- // overloaded function in an expression, as in the asserts below. See ARM pg. 327
- // for legal uses of the address of an overloaded function.
-
- __FW_OperatorNewHandler newHandler = &::operator new;
- __FW_OperatorDeleteHandler deleteHandler = &::operator delete;
-
- FW_ASSERT(excGlobals.gOperatorNewHandler == newHandler);
- FW_ASSERT(excGlobals.gOperatorDeleteHandler == deleteHandler);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemoryTaskGlobals::Terminate()
- //----------------------------------------------------------------------------------------
-
- void FW_CMemoryTaskGlobals::Terminate()
- {
- TerminateMemoryHeap();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CMemoryTaskGlobals::SetMemoryHeap()
- //----------------------------------------------------------------------------------------
-
- void FW_CMemoryTaskGlobals::SetMemoryHeap(FW_CMemoryHeap *aMemoryHeap)
- {
- GetMemoryGlobals().gMemoryHeap = aMemoryHeap;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemoryTaskGlobals::InitializeMemoryHeap()
- //----------------------------------------------------------------------------------------
- #ifdef FW_BUILD_MAC
- pascal long GetA5() = { 0x2e8d };
- #endif
-
- void FW_CMemoryTaskGlobals::InitializeMemoryHeap(FW_SPrivMemoryGlobals& memGlobals)
- {
- const unsigned long kDefaultHeapSize = 10L * 1024L;
- const unsigned long kDefaultHeapIncrementSize = 25L * 1024L;
-
- #ifdef FW_qUsePlatformAlloc
- memGlobals.gMemoryHeap = NULL;
- memGlobals.gInitialized = 1;
- #else
- FW_CBestFitHeap *heap = new FW_CBestFitHeap(kDefaultHeapSize,
- kDefaultHeapIncrementSize);
- FW_ASSERT(heap != NULL);
-
- memGlobals.gMemoryHeap = heap;
- #ifdef FW_DEBUG
- heap->SetDescription("Default OPF Heap");
- heap->SetZapOnAllocate(TRUE);
- heap->SetZapOnFree(TRUE);
- heap->SetAutoValidation(TRUE);
- #else
- heap->SetZapOnAllocate(FALSE);
- heap->SetZapOnFree(FALSE);
- heap->SetAutoValidation(FALSE);
- #endif
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemoryTaskGlobals::TerminateMemoryHeap()
- //----------------------------------------------------------------------------------------
- void FW_CMemoryTaskGlobals::TerminateMemoryHeap()
- {
- #ifndef FW_qUsePlatformAlloc
- FW_SPrivMemoryGlobals& memGlobals = GetMemoryGlobals();
- delete memGlobals.gMemoryHeap;
- memGlobals.gMemoryHeap = NULL;
- #endif
- }
-